<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
                    xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf"
                    xmlns:dentalConverters="clr-namespace:DentalConfig.Converters;assembly=DentalConfig"
                    xmlns:guiHelper="clr-namespace:DentalGUIHelper;assembly=DentalConfig">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="MaterialDesignTheme.Calendar.xaml" />
        <ResourceDictionary Source="MaterialDesignTheme.ValidationErrorTemplate.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <converters:TextFieldHintVisibilityConverter x:Key="TextFieldHintVisibilityConverter" />
    <converters:MathConverter Operation="Divide" x:Key="DivisionMathConverter" />
    <dentalConverters:IsStringNullOrEmptyConverter x:Key="StringNullOrEmpty"/>

    <Style x:Key="MaterialDesignDatePickerTextBox" TargetType="{x:Type DatePickerTextBox}">
        <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
        <Setter Property="wpf:TextFieldAssist.TextBoxViewMargin" Value="0 0 0 0" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="CaretBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=Foreground}" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePickerTextBox}">
                    <Grid>
                        <Grid.Resources>
                            <SolidColorBrush x:Key="WatermarkBrush" Color="{TemplateBinding Foreground}" />
                        </Grid.Resources>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                    <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="MouseOver" />
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="WatermarkStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Unwatermarked" />
                                <VisualState x:Name="Watermarked">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To=".23" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Watermark" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0" />
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Unfocused" />
                                <VisualState x:Name="Focused" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="WatermarkContent" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                            <wpf:SmartHint x:Name="Hint"
                                           FontSize="{TemplateBinding FontSize}"
                                           UseFloating="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource TemplatedParent}}"
                                           FloatingScale="{Binding Path=(wpf:HintAssist.FloatingScale), RelativeSource={RelativeSource TemplatedParent}}"
                                           FloatingOffset="{Binding Path=(wpf:HintAssist.FloatingOffset), RelativeSource={RelativeSource TemplatedParent}}"
                                           Hint="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource TemplatedParent}}"
                                           HintProxy="{Binding RelativeSource={RelativeSource TemplatedParent}, Converter={x:Static converters:HintProxyFabricConverter.Instance}}"
                                           HintOpacity="{Binding Path=(wpf:HintAssist.HintOpacity), RelativeSource={RelativeSource TemplatedParent}}" />
                            <ContentControl x:Name="PART_Watermark" Focusable="False" IsHitTestVisible="False" Opacity="0" Visibility="Collapsed" />
                            <ScrollViewer x:Name="PART_ContentHost" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="0" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Grid>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="Hint" Property="IsContentNullOrEmpty" Value="False" />
                                <Condition Property="IsKeyboardFocused" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="Hint" Property="Foreground" Value="{DynamicResource MidContrastPrimaryBrush}" />
                            <Setter TargetName="Hint" Property="HintOpacity" Value="1" />
                        </MultiTrigger>
                        <MultiDataTrigger>
                          <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource Self}}" Value="False" />
                            <Condition Binding="{Binding Path=(guiHelper:TextboxHelper.HintIsVisible), RelativeSource={RelativeSource Self}}" Value="False"/>
                          </MultiDataTrigger.Conditions>
                          <Setter TargetName="Hint" Property="Visibility" Value="Collapsed" />
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MaterialDesignDatePickerCalendarPortrait" TargetType="{x:Type Calendar}">
        <Setter Property="Foreground" Value="{DynamicResource MaterialDesignBody}" />
        <Setter Property="Background" Value="{DynamicResource MaterialDesignPaper}" />
        <Setter Property="CalendarDayButtonStyle" Value="{StaticResource MaterialDesignCalendarDayButton}" />
        <Setter Property="CalendarButtonStyle" Value="{StaticResource MaterialDesignCalendarButton}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Calendar}">
                    <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
                        <Border Effect="{DynamicResource MaterialDesignShadowDepth4}" Padding="16 8 16 24">
                            <CalendarItem x:Name="PART_CalendarItem" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Style="{DynamicResource MaterialDesignCalendarItemPortrait}" />
                        </Border>
                    </AdornerDecorator>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MaterialDesignDatePicker" TargetType="{x:Type DatePicker}">
        <Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}" />
        <Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="CalendarStyle" Value="{StaticResource MaterialDesignDatePickerCalendarPortrait}" />
        <Setter Property="IsTodayHighlighted" Value="True" />
        <Setter Property="SelectedDateFormat" Value="Short" />
        <Setter Property="BorderThickness" Value="0 0 0 1" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="Margin" Value="0 0 0 0" />
        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource MaterialDesignValidationErrorTemplate}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type DatePicker}">
                    <Grid>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}"
                                x:Name="border"
                                Padding="0 4 0 4"
                                SnapsToDevicePixels="True">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" To=".56" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Root" />
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Grid x:Name="PART_Root"
                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                  Background="Transparent">
                                <Grid.Resources>
                                    <ControlTemplate x:Key="DropDownButtonTemplate" TargetType="{x:Type Button}">
                                        <Grid Background="Transparent">
                                            <VisualStateManager.VisualStateGroups>
                                                <VisualStateGroup x:Name="CommonStates">
                                                    <VisualStateGroup.Transitions>
                                                        <VisualTransition GeneratedDuration="0" />
                                                        <VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver" />
                                                        <VisualTransition GeneratedDuration="0:0:0.1" To="Pressed" />
                                                    </VisualStateGroup.Transitions>
                                                    <VisualState x:Name="Normal" />
                                                    <VisualState x:Name="MouseOver" />
                                                    <VisualState x:Name="Pressed" />
                                                    <VisualState x:Name="Disabled" />
                                                </VisualStateGroup>
                                            </VisualStateManager.VisualStateGroups>
                                            <Viewbox>
                                                <Canvas Width="24" Height="24">
                                                    <Path Data="M19,19H5V8H19M16,1V3H8V1H6V3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3H18V1M17,12H12V17H17V12Z" Fill="{TemplateBinding Foreground}" />
                                                </Canvas>
                                            </Viewbox>
                                        </Grid>
                                    </ControlTemplate>
                                </Grid.Resources>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <Button x:Name="PART_Button"
                                        Grid.Column="1"
                                        Foreground="{TemplateBinding BorderBrush}"
                                        Focusable="False"
                                        HorizontalAlignment="Right"
                                        Margin="4 0 0 -3"
                                        Grid.Row="0"
                                        Template="{StaticResource DropDownButtonTemplate}" Padding="0"
                                        Height="17" />
                                <DatePickerTextBox x:Name="PART_TextBox"
                                                   Grid.Column="0"
                                                   Focusable="{TemplateBinding Focusable}"
                                                   HorizontalContentAlignment="Stretch"
                                                   Grid.Row="0"
                                                   VerticalContentAlignment="Center"
                                                   Style="{DynamicResource MaterialDesignDatePickerTextBox}"
                                                   HorizontalAlignment="Stretch" />
                                <Popup x:Name="PART_Popup" AllowsTransparency="True"
                                       Placement="Custom"
                                       CustomPopupPlacementCallback="{x:Static wpf:CustomPopupPlacementCallbackHelper.LargePopupCallback}"
                                       PlacementTarget="{Binding ElementName=PART_TextBox}" StaysOpen="False"
                                       PopupAnimation="Fade"  />
                            </Grid>
                        </Border>
                        <Line x:Name="DashedLine" VerticalAlignment="Bottom" Visibility="Hidden"
                              StrokeThickness="{Binding BorderThickness.Bottom, ElementName=border, Converter={StaticResource DivisionMathConverter}, ConverterParameter=0.75}" StrokeDashArray="1,2.5" StrokeDashCap="Round"
                              X1="0" X2="{Binding ActualWidth, ElementName=border}" Y1="0" Y2="0"
                              Stroke="{TemplateBinding BorderBrush}" Opacity="0.56" />
                        <wpf:Underline x:Name="Underline" Visibility="{Binding Path=(wpf:TextFieldAssist.DecorationVisibility), RelativeSource={RelativeSource TemplatedParent}}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Opacity" TargetName="border" Value="0.56" />
                            <Setter Property="Visibility" TargetName="DashedLine"  Value="Visible" />
                            <Setter Property="BorderBrush" TargetName="border" Value="Transparent" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="BorderBrush" Value="{DynamicResource MidContrastPrimaryBrush}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocusWithin" Value="true">
                            <Setter TargetName="Underline" Property="IsActive" Value="True" />
                            <Setter Property="BorderBrush"  Value="{DynamicResource MidContrastPrimaryBrush}" />
                        </Trigger>
                        <Trigger Property="Validation.HasError" Value="true">
                            <Setter Property="BorderBrush" Value="{DynamicResource ValidationErrorBrush}" />
                            <Setter TargetName="Underline" Property="Background" Value="{DynamicResource ValidationErrorBrush}" />
                        </Trigger>
                        <MultiDataTrigger>
                          <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding Path=(wpf:HintAssist.IsFloating), RelativeSource={RelativeSource Self}}" Value="True" />
                            <Condition Binding="{Binding Path=(wpf:HintAssist.Hint), RelativeSource={RelativeSource Self}, Converter={StaticResource StringNullOrEmpty}}" Value="False"/>
                          </MultiDataTrigger.Conditions>
                          <Setter TargetName="border" Property="Margin" Value="0 20 0 0" />
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="MaterialDesignFloatingHintDatePicker" TargetType="{x:Type DatePicker}" BasedOn="{StaticResource MaterialDesignDatePicker}">
        <Setter Property="wpf:HintAssist.IsFloating" Value="True" />
    </Style>

    <Style x:Key="{x:Type DatePicker}" BasedOn="{StaticResource MaterialDesignDatePicker}" TargetType="{x:Type DatePicker}"/>
</ResourceDictionary>
